Skip to content

[v2.12]fix: handle NULL json_str case to avoid undefined behavior#2522

Merged
fengzeroz merged 1 commit into
emqx:v2.12from
ZhouBox:v2.12
Jul 22, 2025
Merged

[v2.12]fix: handle NULL json_str case to avoid undefined behavior#2522
fengzeroz merged 1 commit into
emqx:v2.12from
ZhouBox:v2.12

Conversation

@ZhouBox

@ZhouBox ZhouBox commented Jul 22, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@ZhouBox
ZhouBox requested review from Copilot and fengzeroz July 22, 2025 06:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses a potential undefined behavior issue in the MQTT plugin by adding a NULL check for the json_str variable before using it in string operations. The fix prevents crashes or undefined behavior that could occur when the JSON string generation fails or returns NULL.

  • Adds NULL pointer validation for json_str before calling strlen()
  • Wraps the string length calculation in a conditional block to ensure safe execution

if (json_str != NULL) {
size = strlen(json_str);
}
}

Copilot AI Jul 22, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closing brace appears to be misaligned or creates unbalanced braces. The NULL check for json_str should wrap only the strlen() operation, but this closing brace suggests it may be closing an outer scope incorrectly.

Suggested change
}

Copilot uses AI. Check for mistakes.
@codecov-commenter

codecov-commenter commented Jul 22, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.66%. Comparing base (9cca71b) to head (f7abe05).

Additional details and impacted files
@@            Coverage Diff             @@
##            v2.12    #2522      +/-   ##
==========================================
- Coverage   66.71%   66.66%   -0.05%     
==========================================
  Files         121      121              
  Lines       27550    27551       +1     
==========================================
- Hits        18379    18368      -11     
- Misses       9171     9183      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fengzeroz
fengzeroz merged commit 5c49db7 into emqx:v2.12 Jul 22, 2025
29 of 36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants